package CutLoad.transitions
{
	/**
	 * 重现效果
	 * <br>数据记录:它会一系列效果值记录在一个数组里，然后顺序或反序的播放一次
	 * @author smallerbird mail:smallerbird@gmail.com  site:www.mkigm.com QQ群:49983196
	 * 
	 */
	public class Record extends TBase
	{
		private var data:Array;
		private var index:Number;
		private var isAd:Boolean;
		/**
		 *  初始化
		 * @param isAd 是顺序还是倒序  默认是倒序
		 * 
		 */		
		public function Record(data:Array=null,isAd:Boolean=false)
		{
			if(data==null) data=new Array();
			this.data=data;
			index=0;
			setIsAd(isAd);
		}
		/**
		 * 记录数据
		 * @param num
		 * 
		 */		
		public function push(num:Number):void{
			data.push(num);
		}
		/**
		 * 是顺序还是倒序 
		 * @param isAd true顺序  false 倒序 
		 * 
		 */		
		public function setIsAd(isAd:Boolean=true):void{
			if(this.isAd){
				index=0
			}else{
				index=data.length-1
			}
			this.isAd=isAd;
		}
		override public function start(someData:TransitionsData=null):void{
			if(data.length==0) return;
			if(this.isAd){
				index=0
			}else{
				index=data.length-1
			}
			cs=1;			
		}
		override public function enterFrame():void{
			if(this.state==0) return;
			if(data.length==0){
				this.stop();
				return;
			}
			var temValue:Number
			temValue=data[index];
			if(this.funEnterFrame!=null) this.funEnterFrame(temValue);
			if(this.isAd){
				index++;
				if(index>data.length-1){
					index=data.length-1
					if(funEnd!=null) this.funEnd(temValue);
					this.stop();
				}
			}else{
				index--;
				if(index<0){
					index=0;
					if(funEnd!=null) this.funEnd(temValue);
					this.stop();
				}
			}
		}
		/**
		 * 
		 * 清0 
		 * 
		 */		
		public function clear():void{
			data=new Array();
		}
		/**
		 * 设置 循环时要调用的外部函数
		 * @param fun 格式:function(当前值:Number):void
		 * 
		 */		
		override public function setFunEnterFrame(fun:Function):void{
			super.setFunEnterFrame(fun);
		}
		/**
		 * 设置结束时要调用的外部函数 
		 * @param fun 格式:function(当前值:Number):void
		 * 
		 */
		override public function setFunEnd(fun:Function):void{
			super.setFunEnd(fun);
		}
		public function toString():String{
			return data.toString();
		}
	}
}